package com.relytosoft.mizar.media.display.services.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.dubhe.common.log.annotation.OpLog;
import com.relytosoft.dubhe.common.log.enums.OpTypeEnum;
import com.relytosoft.mizar.media.display.api.entity.CruiseControl;
import com.relytosoft.mizar.media.display.api.pojo.dto.CruiseTrackDto;
import com.relytosoft.mizar.media.display.services.service.CruiseTrackService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 云台巡航轨迹控制器
 *
 * @author hj
 * @version 1.0
 * @date 2022/4/11 10:11
 * @ClassName PtzCruiseTrackController
 */
@Validated
@RestController
@RequestMapping("display/cruise")
@Api(tags = "云台巡航轨迹控制器")
public class PtzCruiseTrackController {

    @Resource
    private CruiseTrackService cruiseTrackService;

    @ApiOperation("获取巡航轨迹列表")
    @GetMapping("/list")
    @SaCheckPermission("display:cruise:list")
    @OpLog(msg = "根据通道id查询",opType = OpTypeEnum.SELECT)
    public ResponseResult<List<CruiseTrackDto>> getList(@RequestParam(required = true) Integer channelId){
        return ResponseResult.ok(cruiseTrackService.selectListByChannelId(channelId));
    }

    @ApiOperation("添加巡航轨迹")
    @PostMapping("/add")
    @SaCheckPermission("display:cruise:insert")
    @OpLog(msg = "添加巡航轨迹",opType = OpTypeEnum.INSERT)
    public ResponseResult<Void> addTrack(@RequestBody @Valid CruiseTrackDto track){
        boolean save = cruiseTrackService.addCruiseTrack(track);
        if(save) {
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

    @ApiOperation(value = "删除巡航轨迹",notes = "传入轨迹id")
    @DeleteMapping("/{id}")
    @SaCheckPermission("display:cruise:delete")
    @OpLog(msg = "删除巡航轨迹",opType = OpTypeEnum.DELETE)
    public ResponseResult<Void> deleteCruise(@PathVariable Integer id){
        boolean delete = cruiseTrackService.deleteCruiseTrack(id);
        if(delete) {
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

    @ApiOperation(value = "启动/停止巡航")
    @PostMapping("/controlling")
    @SaCheckPermission("display:cruise:control")
    @OpLog(msg = "控制巡航轨迹",opType = OpTypeEnum.OTHER)
    public ResponseResult doCruise(@RequestBody @Valid CruiseControl control){
        boolean bool = cruiseTrackService.doCruise(control);
        if (bool) {
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

    @ApiOperation(value = "修改轨迹")
    @PutMapping("/edit")
    @SaCheckPermission("display:cruise:update")
    @OpLog(msg = "修改巡航轨迹",opType = OpTypeEnum.UPDATE)
    public ResponseResult editCruise(@RequestBody @Valid CruiseTrackDto track){
        boolean update = cruiseTrackService.addCruiseTrack(track);
        if(update){
            return ResponseResult.ok();
        }
        return ResponseResult.fail();
    }

}
